home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / progtool / c / gcc / gempp19.zoo / gem++19 / src / gemsl.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-20  |  5.6 KB  |  306 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  This file is Copyright 1992,1993 by Warwick W. Allison.
  4. //  This file is part of the gem++ library.
  5. //  You are free to copy and modify these sources, provided you acknowledge
  6. //  the origin by retaining this notice, and adhere to the conditions
  7. //  described in the file COPYING.LIB.
  8. //
  9. /////////////////////////////////////////////////////////////////////////////
  10.  
  11. #include "gemsl.h"
  12. #include "gemf.h"
  13. #include "geme.h"
  14. #include "contract.h"
  15. #include <aesbind.h>
  16. #include <minmax.h>
  17.  
  18. const int PAGE_DELAY=250;
  19. const int LINE_DELAY=50;
  20.  
  21.  
  22. class SL_Knob : public GEMobject
  23. {
  24. public:
  25.     SL_Knob(GEMform& f, int RSCindex, GEMslider& tell) :
  26.         GEMobject(f, RSCindex),
  27.         Tell(tell)
  28.     { }
  29.  
  30.     virtual GEMfeedback Touch(int x, int y, const GEMevent&)
  31.     {
  32.         int tx,ty;
  33.  
  34.         Tell.GetAbsoluteXY(tx,ty);
  35.  
  36.         int ox,oy,nx,ny;
  37.         ox=tx+X();
  38.         oy=ty+Y();
  39.  
  40.         graf_dragbox(Width(),Height(),ox,oy,
  41.             tx,ty,Tell.Width(),Tell.Height(),&nx,&ny);
  42.  
  43.         if (ox!=nx || oy!=ny) {
  44.             MoveTo(nx-tx,ny-ty);
  45.             Tell.GEMtoDOC();
  46.             if (ox!=nx) Tell.HFlush();
  47.             if (oy!=ny) Tell.VFlush();
  48.         }
  49.  
  50.         return ContinueInteraction;
  51.     }
  52.  
  53. private:
  54.     GEMslider& Tell;
  55. };
  56.  
  57. static void Untouch(int timeout)
  58. {
  59.     GEMevent event;
  60.     if (event.Button()) {
  61.         event.Interval(timeout); // Wait for timeout
  62.         event.Button(1,0); // or leftbutton release
  63.         event.Get(MU_TIMER|MU_BUTTON);
  64.     }
  65. }
  66.  
  67.  
  68. class SL_Left : public GEMobject
  69. {
  70. public:
  71.     SL_Left(GEMform& f, int RSCindex, GEMslider& tell) :
  72.         GEMobject(f, RSCindex),
  73.         Tell(tell)
  74.     { }
  75.  
  76.     virtual GEMfeedback Touch(int x, int y, const GEMevent&)
  77.     {
  78.         Tell.ColumnLeft();
  79.         Tell.HFlush();
  80.         Untouch(Tell.LineDelay(-1));
  81.         return ContinueInteraction;
  82.     }
  83.  
  84. private:
  85.     GEMslider& Tell;
  86. };
  87.  
  88.  
  89. class SL_Right : public GEMobject
  90. {
  91. public:
  92.     SL_Right(GEMform& f, int RSCindex, GEMslider& tell) :
  93.         GEMobject(f, RSCindex),
  94.         Tell(tell)
  95.     { }
  96.  
  97.     virtual GEMfeedback Touch(int x, int y, const GEMevent&)
  98.     {
  99.         Tell.ColumnRight();
  100.         Tell.HFlush();
  101.         Untouch(Tell.LineDelay(-1));
  102.         return ContinueInteraction;
  103.     }
  104.  
  105. private:
  106.     GEMslider& Tell;
  107. };
  108.  
  109.  
  110. class SL_Up : public GEMobject
  111. {
  112. public:
  113.     SL_Up(GEMform& f, int RSCindex, GEMslider& tell) :
  114.         GEMobject(f, RSCindex),
  115.         Tell(tell)
  116.     { }
  117.  
  118.     virtual GEMfeedback Touch(int x, int y, const GEMevent&)
  119.     {
  120.         Tell.LineUp();
  121.         Tell.VFlush();
  122.         Untouch(Tell.LineDelay(-1));
  123.         return ContinueInteraction;
  124.     }
  125.  
  126. private:
  127.     GEMslider& Tell;
  128. };
  129.  
  130.  
  131. class SL_Down : public GEMobject
  132. {
  133. public:
  134.     SL_Down(GEMform& f, int RSCindex, GEMslider& tell) :
  135.         GEMobject(f, RSCindex),
  136.         Tell(tell)
  137.     { }
  138.  
  139.     virtual GEMfeedback Touch(int x, int y, const GEMevent&)
  140.     {
  141.         Tell.LineDown();
  142.         Tell.VFlush();
  143.         Untouch(Tell.LineDelay(-1));
  144.         return ContinueInteraction;
  145.     }
  146.  
  147. private:
  148.     GEMslider& Tell;
  149. };
  150.  
  151.  
  152.  
  153. GEMslider::GEMslider(GEMform& f, int RSCknob, int RSCrack) :
  154.     GEMobject(f,RSCrack),
  155.     GEMpanarea(f[RSCknob].Height(),Height(),f[RSCknob].Width(),Width()),
  156.     K(new SL_Knob(f,RSCknob,*this)),
  157.     U(0),D(0),L(0),R(0),
  158.     page_delay(PAGE_DELAY), line_delay(LINE_DELAY)
  159. {
  160.     GEMtoDOC();
  161. }
  162.  
  163. GEMslider::GEMslider(GEMform& f, int RSCknob, int RSCrack, int RSCminus, int RSCplus) :
  164.     GEMobject(f,RSCrack),
  165.     GEMpanarea(f[RSCknob].Height(),Height(),f[RSCknob].Width(),Width()),
  166.     K(new SL_Knob(f,RSCknob,*this)),
  167.     U(0),D(0),L(0),R(0),
  168.     page_delay(PAGE_DELAY), line_delay(LINE_DELAY)
  169. {
  170.     GEMtoDOC();
  171.     if (Width()-K->Width() > Height()-K->Height()) {
  172.         // Horizontal
  173.         L=new SL_Left(f,RSCminus,*this);
  174.         R=new SL_Right(f,RSCplus,*this);
  175.     } else {
  176.         // Vertical
  177.         U=new SL_Up(f,RSCminus,*this);
  178.         D=new SL_Down(f,RSCplus,*this);
  179.     }
  180. }
  181.  
  182. GEMslider::GEMslider(GEMform& f, int RSCknob, int RSCrack,
  183.         int RSChminus, int RSChplus,
  184.         int RSCvminus, int RSCvplus) :
  185.     GEMobject(f,RSCrack),
  186.     GEMpanarea(f[RSCknob].Height(),Height(),f[RSCknob].Width(),Width()),
  187.     K(new SL_Knob(f,RSCknob,*this)),
  188.     L(new SL_Left(f,RSChminus,*this)),
  189.     R(new SL_Right(f,RSChplus,*this)),
  190.     U(new SL_Up(f,RSCvminus,*this)),
  191.     D(new SL_Down(f,RSCvplus,*this)),
  192.     page_delay(PAGE_DELAY), line_delay(LINE_DELAY)
  193. {
  194.     GEMtoDOC();
  195. }
  196.  
  197. GEMslider::~GEMslider()
  198. {
  199.     delete K;
  200.     if (U) delete U;
  201.     if (D) delete D;
  202.     if (L) delete L;
  203.     if (R) delete R;
  204. }
  205.  
  206. GEMfeedback GEMslider::Touch(int x, int y, const GEMevent&)
  207. {
  208.     if (x<K->X()) {
  209.         PageLeft();
  210.         HFlush();
  211.     } else if (x>=K->X()+K->Width()) {
  212.         PageRight();
  213.         HFlush();
  214.     }
  215.     if (y<K->Y()) {
  216.         PageUp();
  217.         VFlush();
  218.     } else if (y>=K->Y()+K->Height()) {
  219.         PageDown();
  220.         VFlush();
  221.     }
  222.     Untouch(page_delay);
  223.     return ContinueInteraction;
  224. }
  225.  
  226. void GEMslider::GEMtoDOC()
  227. {
  228.     SetTopLine(Height() > K->Height()
  229.         ? K->Y()*(TotalLines()-VisibleLines())/(Height()-K->Height())
  230.         : 0
  231.     );
  232.  
  233.     SetLeftColumn(Width() > K->Width()
  234.         ? K->X()*(TotalColumns()-VisibleColumns())/(Width()-K->Width())
  235.         : 0
  236.     );
  237. }
  238.  
  239. void GEMslider::VFlush()
  240. {
  241.     int y,h;
  242.     VGetScaledValue(Height(),h,y);
  243.     K->SetHeight(h);
  244.     K->MoveTo(K->X(),y);
  245.     Redraw();
  246. }
  247.  
  248. void GEMslider::HFlush()
  249. {
  250.     int x,w;
  251.     HGetScaledValue(Width(),w,x);
  252.     K->SetWidth(w);
  253.     K->MoveTo(x,K->Y());
  254.     Redraw();
  255. }
  256.  
  257. void GEMslider::SetVisibleLines(int noOfLines)
  258. {
  259.     GEMpanarea::SetVisibleLines(noOfLines);
  260.     //VFlush();
  261. }
  262.  
  263. void GEMslider::SetTotalLines(int noOfLines)
  264. {
  265.     GEMpanarea::SetTotalLines(noOfLines);
  266.     //VFlush();
  267. }
  268.  
  269. void GEMslider::SetTopLine(int noOfLine)
  270. {
  271.     GEMpanarea::SetTopLine(noOfLine);
  272.     //VFlush();
  273. }
  274.  
  275. void GEMslider::SetVisibleColumns(int noOfColumns)
  276. {
  277.     GEMpanarea::SetVisibleColumns(noOfColumns);
  278.     //HFlush();
  279. }
  280.  
  281. void GEMslider::SetTotalColumns(int noOfColumns)
  282. {
  283.     GEMpanarea::SetTotalColumns(noOfColumns);
  284.     //HFlush();
  285. }
  286.  
  287. void GEMslider::SetLeftColumn(int noOfColumn)
  288. {
  289.     GEMpanarea::SetLeftColumn(noOfColumn);
  290.     //HFlush();
  291. }
  292.  
  293. int GEMslider::LineDelay(int ms)
  294. {
  295.     int r=line_delay;
  296.     if (ms>=0) line_delay=ms;
  297.     return r;
  298. }
  299.  
  300. int GEMslider::PageDelay(int ms)
  301. {
  302.     int r=page_delay;
  303.     if (ms>=0) page_delay=ms;
  304.     return r;
  305. }
  306.